//
//  PhotoViewController.m
//  HWSGW
//
//  Created by avachen on 15/11/6.
//  Copyright © 2015年 luxuanrui. All rights reserved.
//

#import "PhotoViewController.h"
#import "PhotoCollectionView.h"

@interface PhotoViewController ()

@end

@implementation PhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.backgroundColor = [UIColor orangeColor];
    _isHide = NO;
    
    //设置导航栏半透明
    UINavigationBar *navigation =  self.navigationController.navigationBar;
    [navigation setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    navigation.barStyle = UIBarStyleBlack;
    //设置半透明
    navigation.translucent = YES;
    
    //创建返回按钮
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    
    self.navigationItem.leftBarButtonItem = backItem;
    
    PhotoCollectionView *collectionView = [[PhotoCollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    collectionView.urls = self.urls;
    collectionView.pagingEnabled = YES;
    //滚动到指定单元格的方法
    [collectionView scrollToItemAtIndexPath:_indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
    
    [self.view addSubview:collectionView];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickAction:) name:KClickNotification object:nil];
    
        // Do any additional setup after loading the view.
}
//单击隐藏显示导航栏的实现
- (void)clickAction:(NSNotification *)notification{
    _isHide = !_isHide;
    
    [self.navigationController setNavigationBarHidden:_isHide animated:YES];
    
}
//返回到上一个控制器
- (void)backAction{
    [self dismissViewControllerAnimated:YES completion:NULL];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
